import TIM from 'tim-js-sdk'
import TIMUploadPlugin from 'tim-upload-plugin'

const txImSdk = {
    init() {
        const tim = TIM.create({
            SDKAppID: 1400198037
        })
        tim.setLogLevel(0)
        tim.on(TIM.EVENT.SDK_NOT_READY, this.onSdkNotReady);
        tim.on(TIM.EVENT.KICKED_OUT, this.onKickedOut);
        tim.on(TIM.EVENT.ERROR, this.onTIMError);
        tim.on(TIM.EVENT.NET_STATE_CHANGE, this.onNetStateChange);
        tim.on(TIM.EVENT.SDK_RELOAD, this.onSDKReload);
        tim.registerPlugin({'tim-upload-plugin': TIMUploadPlugin})
        uni.$TUIKitTIM = TIM;
        uni.$TUIKitEvent = TIM.EVENT;
        uni.$TUIKitVersion = TIM.VERSION;
        uni.$TUIKitTypes = TIM.TYPES; // 监听系统级事件
        uni.$TUIKit = tim

        uni.$aegis={
            reportEvent(){

            }
        }
    },

    onTIMError(error) {
        console.log("腾讯IM:", `onTIMError----->${error}`)
    },
    // onSDKReady({name}) {
    //     this.isSDKReady = name === uni.$TUIKitEvent.SDK_READY
    //     console.log("腾讯IM:", `onSDKReady----->${this.isSDKReady}`)
    //     uni.$emit('isSDKReady', {
    //         isSDKReady: this.isSDKReady
    //     });
    // },
    onNetStateChange() {
        console.log("腾讯IM:", 'onNetStateChange----->')
    },
    onSDKReload() {
        console.log("腾讯IM:", 'onSDKReload----->')
    },
    onSdkNotReady() {
        console.log("腾讯IM:", 'onSdkNotReady----->')
    },
    onKickedOut() {
        console.log("腾讯IM:", 'onKickedOut----->')
    }
}
export default txImSdk
